import type { MultipleConditionSearchSchema } from '@/components/multiple-condition-search'

import { LicenseSourceOptions } from '@/constants/cdn-node'

export default function useConfig() {
  const searchSchema = computed<MultipleConditionSearchSchema>(() => {
    return {
      placeholder: '默认按照证书域名搜索',
      widgets: [
        {
          type: 'input',
          label: '证书域名',
          field: 'domain_keyword',
          maxLength: 30,
        },
        {
          type: 'input',
          label: '证书品牌',
          field: 'brand_keyword',
        },
        {
          type: 'select',
          label: '证书来源',
          field: 'source',
          placeholder: 'source',
          options: LicenseSourceOptions,
        },
        // {
        //   dataIndex: 'operated_at',
        //   title: '过期时间',
        //   maxWidth: 180,
        //   sortable: sortableSettings,
        //   format: 'date-time',
        // },
        // {
        //   label: '过期时间',
        //   dataIndex: 'created_at',
        //   sortable: sortableSettings,
        //   format: 'date-time',
        //   type: 'date-time',
        // },
      ],
    }
  })

  const tableColumns = buildColumns([
    {
      title: '证书域名',
      dataIndex: 'domain',
      slotName: 'domain',
      width: 194,
    },
    {
      title: '所属应用',
      dataIndex: 'app_id',
      slotName: 'appId',
      width: 220,
    },
    {
      title: '证书品牌',
      dataIndex: 'brand',
      width: 220,
    },
    {
      title: '证书来源',
      dataIndex: 'source',
      slotName: 'source',
      width: 120,
    },
    {
      title: '自动续签',
      dataIndex: 'auto_renew',
      slotName: 'auto_renew',
      width: 120,
    },

    {
      title: '最近更新',
      dataIndex: 'record_created_at',
      // format: 'date-time',
      sortable: sortableSettings,
      slotName: 'updated_at',
      width: 260,
    },
    {
      title: '过期时间',
      dataIndex: 'expired_at',
      slotName: 'expired_at',
      // format: 'date-time',
      sortable: sortableSettings,
      width: 260,
    },
    {
      title: '操作',
      fixed: 'right',
      slotName: 'actions',
      width: 80,
      cellClass: 'actions-cell',
    },
  ])

  return {
    searchSchema,
    tableColumns,
  }
}
